
const USER_KEY = "USER-DATA"
const REMEMBER_ME_KEY = "REMEMBER_ME-DATA"

export default {
    getToken: function() {
        if (process.client) {
            const authInfo = localStorage.getItem(USER_KEY)
            if (authInfo) {
                const authInfoJson = JSON.parse(authInfo)
                return authInfoJson.token
            }
        }
        return ''
    },
    getLocalUser: function() {
        if(process.client){
            const authInfo = localStorage.getItem(USER_KEY)
            if(authInfo){
                const authInfoJson = JSON.parse(authInfo)
                return authInfoJson.user
            }
        }
        return null
    },
    clearAuthInfo: function() {
        if (process.client) {
            localStorage.removeItem(USER_KEY)
        }
    },
    getRememberMeObj: function(){
        if(process.client){
            const authInfo = localStorage.getItem(REMEMBER_ME_KEY)
            if(authInfo){
                const authInfoJson = JSON.parse(authInfo)
                return authInfoJson.rememberMeObj
            }
        }
        return {
            rememberMe: false,
            account: '',
            password: ''
        }
    }
}
